# -*- coding: utf-8 -*-
from PyQt4 import QtGui, QtCore

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s


from ui.uiVnaPlotter import UiVnaPlotter
from gpib.prologixGpibEthernet import GPIB
from actions.actionsVna8712et import ActionsVNA8712ET
from actions.actionsVna8714c import ActionsVNA8714C
from actions.actionsVna8753e import ActionsVNA8753E
from db.dataBase import DataBase


class RunnerUiVnaPlotter(QtGui.QMainWindow):

    def __init__(self, modeloVna):
        """
            Construtor da classe.
        """
        QtGui.QMainWindow.__init__(self)
        self.modeloVna = modeloVna
        self.setupUi()



    def setupUi(self):
        """
            Instancia e inicia os modulos necessarios.
        """
        self.ui = UiVnaPlotter()
        self.ui.setupUi(self)
        self.db = DataBase()
        self.uiPrologix = GPIB(self.ui)
        self.actionsVna(self.modeloVna)



    def actionsVna(self, modeloVna):
        """
            Metodo que instancia a classe com as acoes do network. Sao passadas
            como argumento a variavel modeloVna, que contem o modelo no VNA e a
            variavel path que tem o caminho do diretorio src, o diretorio raiz 
            do aplicativo.
        """
        if modeloVna == "8712ET":
            self.uiActionsVNA = ActionsVNA8712ET(self.ui, self.db)
            self.run()
        
        elif modeloVna == "8714C":
            self.uiActionsVNA = ActionsVNA8714C(self.ui, self.db)
            self.run()
        
        elif modeloVna == "8753E":
            self.uiActionsVNA = ActionsVNA8753E(self.ui, self.db)
            self.run()
        
        elif modeloVna == None:
            QtGui.QMessageBox.warning(None,
                                      " TSM ",
                                      _fromUtf8(
                                      "Network desligado!"))
        
        else:
            QtGui.QMessageBox.warning(None,
                                      " TSM ",
                                      _fromUtf8(
                                      "Network não conectado!"))



    def run(self):
        """
            Metodo para rodar a aplicacao.
        """
        self.ui.uiVna.show()
